from Tkinter import *
import tkSimpleDialog as tks
import tkFileDialog as tkf
import tkMessageBox as tkm
class fp(object):
    def __init__(self, toto):
        self.selectionne=0
        self.root=Tk()
        self.toto=toto
        self.frameJeu=Frame(self.root)
        self.canvasJeu = Canvas(self.frameJeu, height=800, width=1200, bg="black")
        self.canvasJeu.pack()
        self.menuUnite = Button(self.frameJeu, text="Unites", command = self.listUnite)
        self.menuUnite.place(x=35, y=775)
        self.menuStructure = Button(self.frameJeu, text="Structures", command = self.listStructure)
        self.menuStructure.place(x=150, y=775)
        self.canvasJeu.create_oval(525, 650, 675, 800, fill="black", outline="white")
        self.canvasJeu.create_rectangle(525, 630, 675, 655, fill="white")
        self.canvasJeu.create_text(600, 642, font = ("Arial", 16), text = "Mini-Map")
        for i in range(len(self.toto)):
            if i == self.selectionne:
                self.canvasJeu.create_oval(self.toto[i].x*100, self.toto[i].y*100, self.toto[i].x*100+10, self.toto[i].y*100+10, fill="yellow")
            else:
                self.canvasJeu.create_oval(self.toto[i].x*100, self.toto[i].y*100,self.toto[i].x*100+10, self.toto[i].y*100+10, fill="red")
        self.canvasJeu.bind("<ButtonPress-1>", self.selection)
        self.canvasJeu.bind("<ButtonPress-3>", self.deplacer)
        self.frameJeu.pack()
        self.uniteBool=False
        self.structureBool=False
        for i in self.parent.modele.univers.etoile:
            self.canvasJeu.create_oval(i.x*10, i.y*10,i.x*10+5, i.y*10+5, fill="blue", outline="white" )
        self.root.mainloop()
        
    def selection(self, event):
        for i in range(len(self.toto)):
            if (event.x>=(self.toto[i].x*100)) and (event.x<=(self.toto[i].x*100)+10) and (event.y>=(self.toto[i].y*100)) and (event.y<=(self.toto[i].y*100)+10):
                self.selectionne = i
                self.canvasJeu.create_oval(self.toto[i].x*100, self.toto[i].y*100, self.toto[i].x*100+10, self.toto[i].y*100+10, fill="yellow")
            else:
                self.canvasJeu.create_oval(self.toto[i].x*100, self.toto[i].y*100, self.toto[i].x*100+10, self.toto[i].y*100+10, fill="red")
    
    def listUnite(self):
        if self.uniteBool == False:
            self.listUnites=Listbox(self.frameJeu)
            for self.unites  in  ["grunt", "proto-grunt"]:
                self.listUnites.insert(END,self.unites)
            self.listUnites.place(x=5, y=600)
            self.uniteBool = True
        else:
            self.listUnites.destroy()
            self.uniteBool=False
    
    def listStructure(self):
        if self.structureBool == False:
            self.listStructures=Listbox(self.frameJeu)
            for self.structures in ["StationSpatial", "CentreEchange", "ExtracteurS", "CMilitaire", "CSciences", "UAttack", "UDefense", "Bob", "Bobby", "lol", "hah", "goHabsgo"]:
                self.listStructures.insert(END, self.structures)
            self.listStructures.place(x=130, y=600)
            self.structureBool=True
        else:
             self.listStructures.destroy()
             self.structureBool=False
             
    def deplacer(self, event):
        parent.initMouvement(selectionne, toto[selectionne].x, toto[selectionne].y, 1)

class miniUnite(object):
    def __init__(self, x, y):
        self.x=x
        self.y=y
tabUnites=[]
for i in range(10):
    tabUnites.append(miniUnite(i,i))
    
f = fp(tabUnites)